package com.zlp.mall.modules.cms.controller;


import com.zlp.mall.common.api.Pager;
import com.zlp.mall.common.api.R;
import com.zlp.mall.modules.cms.dto.resp.SubjectResp;
import com.zlp.mall.modules.cms.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商品专题管理
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/subject")
@Api(value = "SubjectController", tags = "商品专题管理")
public class SubjectController {

    private final SubjectService subjectService;

    @ApiOperation("获取全部商品专题")
    @GetMapping(value = "/listAll")
    public R<List<SubjectResp>> listAll() {

        List<SubjectResp> subjectList = subjectService.listAll();
        return R.success(subjectList);
    }

    @GetMapping(value = "/list")
    @ApiOperation(value = "根据专题名称分页获取专题")
    public R<Pager<SubjectResp>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Pager<SubjectResp> pager = subjectService.getPageList(keyword, pageNum, pageSize);
        return R.success(pager);
    }
}
